package juc练习;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerDemo {

    private static AtomicInteger count = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    count.getAndIncrement();
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    count.getAndIncrement();
                }
            }
        });
        t1.start();
        t2.start();
        //main线程等待t1，t2都执行完
        t1.join();
        t2.join();
        //看看count的值
        System.out.println(count);
    }
}
